{if condition="$instance['instancestatus'] neq 0"}
<style>
    .flowcontent input {
        pointer-events: none;
        border: 1px solid #DDD;
        background-color: #F5F5F5;
    }

    .flowcontent select {
        pointer-events: none;
        border: 1px solid #DDD;
        background-color: #F5F5F5;
    }

    .flowcontent textarea {
        pointer-events: none;
        border: 1px solid #DDD;
        background-color: #F5F5F5;
    }

</style>
{/if}
<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <input type="hidden" id="taskid" name="taskid" value="{$task->id ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="ids" name="ids" value="{$ids ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="flowcode" name="flowcode" value="{$flowCode ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="table" name="table" value="{$table ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="status" value="{$model.status ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="vacation_id" name="vacation_id" value="{$model.id ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="is_number" name="is_number" value="{$model.is_number ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="is_corresponding" name="is_corresponding" value="{$model.corresponding ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="sum_jbd" name="sum_jbd" value="{$model.sum_jbd ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <div class="layui-row">
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">申请人</label>
                <div class="layui-input-block">
                    <input type="text" value="  {$originator.nickname ?? ''}" required placeholder="申请人"
                           autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">申请部门</label>
                <div class="layui-input-block">
                    <input type="text" value="{$model.group_name ?? ''}" required placeholder="申请部门"
                           autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">申请日期</label>
                <div class="layui-input-block">
                    <input type="text" value="  {$model.create_time ?? ''}" required placeholder="申请日期"
                           autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">请假类型</label>
                <div class="layui-input-block">
                    <input type="text" isxsj="1" id="alternative_title" name="alternative_title" value="{$model.alternative_title ?? '事假'}" required placeholder="请假类型"
                           autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">时间范围</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <input type="text" isxsj="1" name="start_time" id="start_time" value="{$model.start_time ??''}" required
                               placeholder="请输入开始时间"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" isxsj="1" name="end_time" id="end_time" value="{$model.end_time ??''}" required
                               placeholder="请输入结束时间"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
        </div>
        {if $model.alternative_title eq '调休'}
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" id="dy_time">
            <!--            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">-->
            <!--                <div class="layui-form-item">-->
            <!--                    <label class="layui-form-label">对应加班单</label>-->
            <!--                    <div class="layui-input-block">-->
            <!--                        <div id="demo1" class="xm-select-demo"></div>-->
            <!--                    </div>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="layui-form-item">
                <label class="layui-form-label">对应时间</label>

                <div class="layui-input-block">
                    <div id="demo2" class="xm-select-demo"></div>
                </div>
            </div>
        </div>
        {/if}
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item ">
                <label class="layui-form-label">
                    {if $model.alternative_title eq '调休'}
                        调休小时数
                    {else /}
                        请假天数
                    {/if}
                </label>
                <div class="layui-input-block">
                    <input type="text" isxsj="1"  id="day" name="day" value="{$model.day ?? ''}" required placeholder="天数"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item ">
                <label class="layui-form-label">{$model.alternative_title ?? '请假'}事由</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea" isxsj="1" id="remark" name="remark">{$model.remark ?? ''}</textarea>
                </div>
            </div>
        </div>
        <!--        {if condition="$schme['flowcode'] eq 'journal' and $schme['flowname'] eq '日志'"}-->
        <!--        <div class="layui-form-item">-->
        <!--            <label class="layui-form-label">日志等级</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <select name="journal_level_id" id="level_id" lay-search="">-->
        <!--                    <option value="">请选择日志类别</option>-->
        <!--                    {foreach $journal_level as $key=>$vo}-->
        <!--                    <option value="{$vo.id}">{$vo.name}</option>-->
        <!--                    {/foreach}-->
        <!--                </select>-->
        <!--            </div>-->
        <!--        </div>-->
        <!--        {/if}-->
        {if condition="$instance['instancestatus'] neq 2"}
        <div class="layui-form-item">
            <label class="layui-form-label">审批意见</label>
            <div class="layui-input-block">
                <textarea id="comment" class="layui-textarea" data-use-current="true" name="comment"></textarea>
            </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <label class="layui-form-label">审批历史</label>
            <div class="layui-input-block">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <td>审批人</td>
                        <td>审批步骤</td>
                        <td>审批意见</td>
                        <td>审批时间</td>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="history" id="vo" }
                    <tr>
                        <td>{$vo.nickname}</td>
                        <td>{$vo.stepname}</td>
                        <td>{$vo.comment}</td>
                        <td>{$vo.completedtime}</td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="form-group layer-footer">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="layui-input-block">
                {if condition="$mode neq 'view'"}
                {if condition="$instance['instancestatus'] eq 0"}
                <button type="button" id='start' class="layui-btn">提交</button>
                {elseif condition="$instance['instancestatus'] eq 1"/}
                <button type="submit" id='agree' class="layui-btn btn-success btn-embossed disabled"
                        style="background-color: #18bc9c !important; border-radius: 5px;">同意
                </button>
                <button type="submit" id='refuse' class="layui-btn btn-danger btn-embossed disabled"
                        style="background-color: #e74c3c !important; border-radius: 5px;">拒绝
                </button>
                {else/}
                {/if}
                {/if}
                <!--            {if condition="$instance['instancestatus'] neq 2 and $instance['instancestatus'] neq 3 and $instance['originator'] eq $auth->id"}-->
                <!--                 <button type="submit" id='cancel' class="layui-btn btn-danger btn-embossed disabled"style="background-color: #e74c3c !important; border-radius: 5px;">取消</button>-->
                <!--            {/if}-->
                <button type="button" id='flowchart' class="layui-btn layui-btn-warm btn-embossed"
                        style="background-color: #f39c12 !important; border-radius: 5px;">流程图
                </button>
            </div>
        </div>
    </div>
</div>
　<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="/static/admin/layui/layui.js"></script>
<script src="/static/xm-select.js"></script>
<script>
    var url = "{:url('Myworkitem/flowchart')}", edit = "{:url('Myworkitem/edit')}",
        refuse = "{:url('Myworkitem/refuse')}", check = "{:url('Myworkitem/check')}";
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
    }).use(['index', 'form', 'laydate', 'flow'], function () {
        var $ = layui.$, form = layui.form, laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#start_time'
            , type: 'datetime'
            , format: "yyyy-MM-dd HH:mm"
            , trigger: 'click'//呼出事件改成click

        });
        var is_number = $('#is_number').val();
        console.log(is_number)
        var is_corresponding = $('#is_corresponding').val();
        var is_corresponding_arr = $('#is_corresponding').val();
        var stringResult = is_corresponding_arr.split(',');
        var  sum_jbd = $('#sum_jbd').val();
        var status = $('#status').val();
        if (status == -1){
            var disabled = false;
        }else{
            var disabled = true;
        }
        var demo2 = '';
        if (is_number == 2 || sum_jbd > 0) {
            $.ajax({
                url: "{:url('overtime/treeList')}",
                type: 'post',
                data: {ids: is_corresponding,status:status},
                dataType: 'json',
                success: function (res) {
                    demo2 =  xmSelect.render({
                        el: '#demo2',
                        name: 'corresponding',
                        direction: 'auto',
                        initValue: stringResult,
                        data: res
                    })
                }
            })
        }
        //日期范围
        laydate.render({
            elem: '#end_time'
            , type: 'datetime'
            , format: "yyyy-MM-dd HH:mm"
            , trigger: 'click'//呼出事件改成click


        });
        // //日期范围
        // laydate.render({
        //     elem: '#dy_start_time'
        //     , type: 'datetime'
        //     , format: "yyyy-MM-dd HH:mm"
        //     , trigger: 'click'//呼出事件改成click
        //
        // });
        // //日期范围dy_end_time
        // laydate.render({
        //     elem: '#dy_end_time'
        //     , type: 'datetime'
        //     , format: "yyyy-MM-dd HH:mm"
        //     , trigger: 'click'//呼出事件改成click
        // });

        var taskid = $('#taskid').val();
        var ids = $('#ids').val();
        var flowcode = $('#flowcode').val();
        var table = $('#table').val();
        var param = $.param({'taskid': taskid, 'ids': ids, 'flowcode': flowcode});

        if (status != -1 || status != "-1") {
            $("[isxsj='1']").attr("disabled", true)
        }
        $('#agree').on('click', function (res) {
            var comment = $('#comment').val();
            // var select = $('#level_id').val();
            $.ajax({
                url: edit,
                type: "post",
                data: {
                    'taskid': taskid,
                    'ids': ids,
                    'flowcode': flowcode,
                    'table': table,
                    'comment': comment,
                    'status': status
                },
                // beforeSend: function () {
                //     layer.load(2, {
                //         shade: [0.6, '#fff'], content: '数据提交中...', success: function (layero) {
                //             layero.find('.layui-layer-content').css({
                //                 'padding-top': '6px',
                //                 'width': '150px',
                //                 'padding-left': '40px'
                //             });
                //             layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                //                 'width': '150px !important',
                //                 'background-position': '2px 0 !important'
                //             });
                //         }
                //     });
                // },
                success: function (res) {
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.closeAll();		//关闭窗口
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                }
            });
        });
        $('#refuse').on('click', function (res) {
            var comment = $('#comment').val();
            $.ajax({
                url: refuse,
                type: "post",
                data: {
                    'taskid': taskid,
                    'ids': ids,
                    'flowcode': flowcode,
                    'table': table,
                    'comment': comment
                },
                // beforeSend: function () {
                //     layer.load(2, {
                //         shade: [0.6, '#fff'], content: '数据提交中...', success: function (layero) {
                //             layero.find('.layui-layer-content').css({
                //                 'padding-top': '6px',
                //                 'width': '150px',
                //                 'padding-left': '40px'
                //             });
                //             layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                //                 'width': '150px !important',
                //                 'background-position': '2px 0 !important'
                //             });
                //         }
                //     });
                // },
                success: function (res) {
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.closeAll();		//关闭窗口
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                }
            });
        });
        $('#flowchart').on('click', function (res) {
            layer.open({
                type: 2
                , title: "流程图"
                , content: url + '?' + param
                , area: ['70%', '70%']
                , maxmin: true
            });
        });
        $('#cancel').on('click', function (res) {
            console.log("取消");
        });

        $('#start').on('click', function (res) {

            var comment = $('#comment').val();
            var vacation_id = $('#vacation_id').val(); //更改主题id
            var alternative_title = $('#alternative_title').val();
            var start_time = $('#start_time').val();
            var end_time = $('#end_time').val();
            var day = $('#day').val();
            if (alternative_title == "调休") {
                var selectArr = demo2.getValue('value');
                var corresponding = selectArr;
                // var corresponding = $('#corresponding').val();
                // console.log(corresponding)
            }
            var remark = $('#remark').val();
            $.ajax({
                url: edit,
                type: "post",
                data: {
                    'taskid': taskid,
                    'ids': ids,
                    'flowcode': flowcode,
                    'table': table,
                    'comment': comment,
                    'vacation_id': vacation_id,
                    'alternative_title': alternative_title,
                    'start_time': start_time,
                    'end_time': end_time,
                    'corresponding': corresponding,
                    'remark': remark,
                    'status': status,
                    'day':day,
                },
                // beforeSend: function () {
                //     layer.load(2, {
                //         shade: [0.6, '#fff'], content: '数据新增中...', success: function (layero) {
                //             layero.find('.layui-layer-content').css({
                //                 'padding-top': '6px',
                //                 'width': '150px',
                //                 'padding-left': '40px'
                //             });
                //             layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                //                 'width': '150px !important',
                //                 'background-position': '2px 0 !important'
                //             });
                //         }
                //     });
                // },
                success: function (res) {
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.closeAll();		//关闭窗口
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                }
            });
        });
        $('#check').on('click', function (res) {
            layer.open({
                type: 2
                , title: "查看{$schme['flowname']}({$instance['instancecode']})"
                , content: check + '?' + param
                , area: ['80%', '80%']
                , maxmin: true
                // , btn: ['确定', '流程图', '取消']
                // , success: function (res) {
                //     console.log(data.instancestatus);
                // }
            });
        })
    });
</script>
